<?php

Yii::app()->clientScript->registerCssfile('http://code.jquery.com/ui/1.10.3/themes/vader/jquery-ui.css');
Yii::app()->clientScript->registerScriptFile('http://code.jquery.com/jquery-1.9.1.js');
Yii::app()->clientScript->registerScriptFile('http://code.jquery.com/ui/1.10.3/jquery-ui.js');
///Yii::app()->clientScript->registerCoreScript('jquery');
//Yii::app()->clientScript->registerCoreScript('jquery.ui');
//Yii::app()->clientScript->registerCss('forMenu','.ui-menu {
//    width: 200px;
//  }');

buildList($catalogs, 0); 

function buildList(&$catalogs, $parentId)
{
   $childrenCatalogs = getChildren($catalogs, $parentId);
   if(count($childrenCatalogs)>0)
   {
        echo CHtml::openTag('ul', $parentId==0?array('id'=>'nemuBar'):array() );   
        foreach ($childrenCatalogs as $childrenCatalog)
        {       
            echo CHtml::openTag('li') . CHtml::link($childrenCatalog->name, array('item/index', 'catalogId'=>$childrenCatalog->id));
            buildList($catalogs, $childrenCatalog->id);      
            echo CHtml::closeTag('li');
        }
        echo CHtml::closeTag('ul');
   }
}

function getChildren(&$catalogs, $parentId)
{
    return array_filter($catalogs, function ($e) use (&$parentId) {
        return $e->parent_id==$parentId;
    });
}

Yii::app()->clientScript->registerScript('menuItems',
'$("#nemuBar").menu();');

?>   

